package edu.umn.se.trap.logicChecker;

import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

import edu.umn.se.trap.Form;
import edu.umn.se.trap.TravelDetails;
import edu.umn.se.trap.OtherExpenses;
import edu.umn.se.trap.exceptions.OtherExpenseException;

public class CheckSyntaxOtherExpense implements Observer {

    @Override
    /**
     * Update for checking syntax for other expenses
     */
    public void update(Observable o, Object arg) {

        LogicChecker l1 = (LogicChecker)o;
        Form form = (Form) arg;
        
        Vector<OtherExpenses> otherExpenses = form.getOtherExpenses();
        TravelDetails travelD = form.getTravelDetails();
           
        int departDate = travelD.getDepartureDate();
        int arrivalDate = travelD.getArrivalDate();
        
        for (int i = 0; i < otherExpenses.size(); i++)
        {
            OtherExpenses otherExp = otherExpenses.get(i);
            int date = Integer.valueOf(otherExp.getDate());
            double amount = otherExp.getAmount();
            String just = otherExp.getJustification();
            
            if (amount <= 0 )
            {
                l1.setException(new OtherExpenseException("Error, amount is not greater than zero"));
            }
            if (just.equals(""))
            {
                l1.setException(new OtherExpenseException("Error, justification not filled."));
            }
        }
    }
}